<template>
  <div class="box">
    <div class="nav">
      <div>
        <img
          src="https://s0.meituan.net/bs/myfe/canary/file/asgard/images/logo@3x.png"
          alt=""
        />
      </div>
      <div>
        <span class="f14 mr10">发现最新最热电影</span>
        <span class="f16">打开APP></span>
      </div>
    </div>
    <div class="flx nav_box bge7 fcff">
      猫眼
      <img
        src="https://p0.meituan.net/scarlett/f05f61e7a8f3f45fd071c068d7a26870356.png"
        alt=""
      />
    </div>
    <div class=" type_box f14">
      <div
        class="flx"
        v-for="(item, index) in typeList"
        :key="index"
        @click="goType(index)"
      >
        {{ item.name }}
        <div v-if="typeactive == index" class="active bge7"></div>
      </div>
    </div>
    <!-- 列表区域 -->
    <div class="video_box" v-for="(item, index) in list" :key="index">
      <!-- 封面 -->
      <div class="cover">
        <img @click="initVideo(index)" :src="item.images[0].url" alt="" />
        <div class="fcff f16 cover_title">{{ item.title }}</div>
      </div>
      <!-- 点赞 -->
      <div class="area">
        <div class="area_left f14 flx">
          <img
            class="mr10"
            src="https://p1.meituan.net/avatar/7398f71d5db514b86623c704f6285c6e122589.jpg"
            alt=""
          />
          猫眼电影
        </div>
        <div class="f14 area_right">
          <div class="flx">
            <img
              class="mr10"
              v-if="item.likeactive"
              @click="like(index, item.like, item.likeactive)"
              src="../../assets/like_.png"
              alt=""
            />
            <img
              class="mr10"
              v-else
              @click="like(index, item.like, item.likeactive)"
              src="../../assets/like.png"
              alt=""
            />
            {{ item.like }}
          </div>
          <div class="flx">
            <img
              class="mr10"
              @click="comments(index, item.comments)"
              src="https://s0.meituan.net/bs/myfe/canary/file/asgard/images/media/video-comment.png"
              alt=""
            />
            {{ item.comments }}
          </div>

          <img
            src="https://s0.meituan.net/bs/myfe/canary/file/asgard/images/media/video-share.png"
            alt=""
          />
        </div>
      </div>
    </div>
    <!-- 列表区域 -->
    <div class="test_two_box" v-if="show" @click="show = false">
      <video @click.stop="" id="myVideo" class="video-js">
        <source :src="videoUrl" type="video/mp4" />
      </video>
    </div>
  </div>
</template>

<script>
// 引入axios对象
import axios from "axios";
// axios.defaults.baseURL = "http://localhost:3000/api";
axios.interceptors.response.use(
  (response) => {
    return response.data || response;
  },
  (error) => {
    return Promise.reject(error);
  }
);
export default {
  data() {
    return {
      list: [],
      typeList: [
        { name: "预告片" },
        { name: "新片看点" },
        { name: "说看点" },
        { name: "佳片看点" },
      ],
      typeactive: "0",
      videoUrl: "",
      show: false,
    };
  },
  methods: {
    async getBegin() {
      const url =
        "/api/list.json?uuid=57C72C00353D11EB89D605B4275B36B67C83404ACDAC496281E5C2BEC96423CE&channelId=4&feedChannelId=1067226&timestamp=1607311951773&offset=15";
      await axios.get(url).then((res) => {

        // console.log(res.feeds);

        const tt=res.feeds
        tt.forEach((item) => {
          item["like"] = "20";
          item["likeactive"] = false;
          item["comments"] = "40";
        });
        this.list = res.feeds;
        // console.log(this.list[0].images);
      });
    },
    goType(index) {
      this.typeactive = index;
    },
    like(index, val, like) {
      // console.log(1111);
      if (like) {
        this.list[index].likeactive = false;
        this.list[index].like = Number(val) - 1;
      } else {
        this.list[index].likeactive = true;
        this.list[index].like = Number(val) + 1;
      }
    },
    comments(index, val) {
      this.list[index].comments = Number(val) + 1;
    },
    initVideo(index) {
      //初始化视频方法
      console.log(index);
      console.log(this.list[index].video.url);
      this.show = true;
      this.videoUrl = this.list[index].video.url;
      setTimeout(() => {
         let myPlayer = this.$video(myVideo, {
        //确定播放器是否具有用户可以与之交互的控件。没有控件，启动视频播放的唯一方法是使用autoplay属性或通过Player API。
        controls: true,
        //自动播放属性,muted:静音播放
        autoplay: "",
        //建议浏览器是否应在<video>加载元素后立即开始下载视频数据。
        preload: "auto",
        //设置视频播放器的显示宽度（以像素为单位）
        width: "375px",
        //设置视频播放器的显示高度（以像素为单位）
        height: "200px",
      });

      }, 500);
     
    },
  },
  mounted() {
    // this.initVideo();
  },
  created() {
    //发起网络请求
    this.getBegin();
    // axios.get(url).then(res=>{console.log(res),console.log(res.data.data)} )
    // console.log("aaaaaa");
  },
};
</script>
<style>
.video-js .vjs-big-play-button {
  left: 138px !important;
  top: 73px !important;
}
</style>
<style lang="scss" scoped>
.f14 {
  font-size: 14px;
}
.f16 {
  font-size: 16px;
}
.fcff {
  color: #fff;
}
.mr10 {
  margin-right: 10px;
}
.bge7 {
  background: #e54847;
}
.flx {
  display: flex;
  justify-content: center;
  align-items: center;
}
.box {
  width: 100%;
  box-sizing: border-box;
  .nav {
    display: flex;
    box-sizing: border-box;
    width: 100%;
    padding: 10px 16px;
    align-items: center;
    justify-content: space-between;
    img {
      width: 94px;
    }
    .mr10 {
      margin-right: 10px;
    }
  }
  .nav_box {
    height: 48px;
    position: relative;
    img {
      width: 20px;
      position: absolute;
      right: 20px;
      top: 14px;
    }
  }
  .type_box {
    height: 40px;
    display: flex;
    align-items: center;
    div {
      width: 80px;
      position: relative;
      .active {
        position: absolute;
        bottom: -6px;
        height: 3px;
        width: 20px;
        border-radius: 20px;
        left: 30px;
      }
    }
  }
  .video_box {
    width: 100%;
    .cover {
      position: relative;
      img {
        width: 100%;
      }
      .cover_title {
        width: 100%;
        overflow: hidden; //超出的文本隐藏
        text-overflow: ellipsis; //溢出用省略号显示
        white-space: nowrap; //溢出不换行
        position: absolute;
        top: 10px;
        left: 0;
      }
    }
    .area {
      width: 100%;
      box-sizing: border-box;
      padding: 10px 20px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .area_left {
        img {
          width: 22px;
        }
      }
      .area_right {
        width: 60%;
        display: flex;
        justify-content: space-around;
        align-items: center;
        img {
          width: 24px;
        }
      }
    }
  }
  .test_two_box {
    width: 100%;
    height: 100vh;
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
  }
}
</style>
